<?php
/**
 * 菜单管理控制器
 * Created by PhpStorm.
 * User: change
 * Date: 2016/12/22
 * Time: 16:09
 */

namespace Admin\Controller;


use Admin\Model\ArticleModel;
use Base\Controller\CurdController;

class ArticleController extends CurdController
{
   protected $model;
    public function __construct($relation = true, $upload = true, $uploadConfig = array(
        'input_name' => 'coverFile',//文本框name
        'save_path' => 'cover',//保存路径
        'data_field' => 'cover'//数据库字段
    ))
    {
        parent::__construct(true, true);
        $this->urlConfig = array(
            'add_success' => U('showList'),
            'add_error' => '',
            'edit_success' => U('showList'),
            'edit_error' => '',
            'del_success' => U('showList'),
            'del_error' => '',
        );
    }

    /**
     * 获取所有数据并注入模板
     * */
    protected function getAll()
    {
//        $map['status'] = 1;
//        $count = $this->model->where($map)->count();
//        $page = new Page($count, 20);
//        $show = $page->show();
        if(I('get.del')){
            $map['status'] = 0;
        }else{
            $map['status'] = 1;
        }
        if(I('get.reviewed')){
            $map['reviewed'] = I('get.reviewed');
            $this->assign('reviewed', I('get.reviewed'));
        }
        if(I('get.column_id')) {
            $map['column_id']=I('get.column_id');
            $this->assign('column_id', I('get.column_id'));
        }
//        $list = $this->model->relation($this->relation)->where($map)->order('id desc')->select();
//        $this->assign('list', $list);
        //文章列表分页
        $articleModel = new ArticleModel();
        $page = $articleModel->pageToView(20, true, $map);
        $this->assign('list', $page['list']);
        $this->assign('page', $page['page']);
    }

}